﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SY.WebApiTool.Model
{
    public class Material
    {
        public string FMATERIALID { get; }
        public Fcreateorgid FCreateOrgId { get; }
        public Fuseorgid FUseOrgId { get; }
        public string FNumber { get; set; } = "";
        public string FName { get; }
        public string FSpecification { get; }
        public string FMnemonicCode { get; }
        public string FOldNumber { get; set; }
        public string FDescription { get; set; }
        public Fmaterialgroup FMaterialGroup { get; set; } 
        public string FImgStorageType { get; set; }
        public string FIsSalseByNet { get; set; }
        public Subheadentity SubHeadEntity { get; set; } = new Subheadentity();
        public Subheadentity1 SubHeadEntity1 { get; set; } = new Subheadentity1();
        public Subheadentity2 SubHeadEntity2 { get; set; } = new Subheadentity2();
        public Subheadentity3 SubHeadEntity3 { get; set; } = new Subheadentity3();
        public Subheadentity4 SubHeadEntity4 { get; set; } = new Subheadentity4();
        public Subheadentity5 SubHeadEntity5 { get; set; } = new Subheadentity5();
        public Subheadentity7 SubHeadEntity7 { get; set; } = new Subheadentity7();
        public Subheadentity6 SubHeadEntity6 { get; set; } = new Subheadentity6();
        public Fentityauxpty[] FEntityAuxPty { get; set; } 
        public Fentityinvpty[] FEntityInvPty { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="useOrgNo"></param>
        /// <param name="createOrgNo"></param>
        /// <param name="number">不指定物料编码时使用默认物料编码规则</param>
        public Material(string name, string useOrgNo, string createOrgNo, string number = "")
        {
            FName = name;
            FNumber = number;
            FUseOrgId = new Fuseorgid() { FNumber = useOrgNo };
            FCreateOrgId = new Fcreateorgid { FNumber = createOrgNo };
        }

        public virtual string JsonData()
        {
            string json = JsonConvert.SerializeObject(this);
            return json;
        }
    }

    public class Fcreateorgid
    {
        public string FNumber { get; set; }
    }

    public class Fuseorgid
    {
        public string FNumber { get; set; }
    }

    public class Fmaterialgroup
    {
        public string FNumber { get; set; }
    }

    public class F_SY_Customer
    {
        public string FNumber { get; set; }
    }

    public class Subheadentity
    {
        public string FBARCODE { get; set; }
        public string FErpClsID { get; set; } = "1";
        public string FCONFIGTYPE { get; set; }
        public Fcategoryid FCategoryID { get; set; } = new Fcategoryid();
        public Ftaxtype FTaxType { get; set; }
        public Ftaxrateid FTaxRateId { get; set; }
        public Fbaseunitid FBaseUnitId { get; set; } = new Fbaseunitid();
        public bool FIsPurchase { get; set; } 
        public bool FIsInventory { get; set; } 
        public bool FIsSubContract { get; set; } 
        public bool FIsSale { get; set; } 
        public bool FIsProduce { get; set; } 
        public bool FIsAsset { get; set; } 
        public decimal FGROSSWEIGHT { get; set; }
        public decimal FNETWEIGHT { get; set; }
        public FWEIGHTUNITID FWEIGHTUNITID { get; set; }
        public FVOLUMEUNITID FVOLUMEUNITID { get; set; }
        public decimal FLENGTH { get; set; }
        public decimal FWIDTH { get; set; }
        public decimal FHEIGHT { get; set; }
        public decimal FVOLUME { get; set; }
    }

    public class Fcategoryid
    {
        public string FNumber { get; set; } = "CHLB01_SYS";
    }

    public class Ftaxtype
    {
        public string FNumber { get; set; }
    }

    public class Ftaxrateid
    {
        public string FNumber { get; set; }
    }

    public class Fbaseunitid
    {
        public string FNumber { get; set; } = "Pcs";
    }

    public class FWEIGHTUNITID
    {
        public string FNumber { get; set; }
    }

    public class FVOLUMEUNITID
    {
        public string FNumber { get; set; }
    }

    public class Subheadentity1
    {
        public Fstoreunitid FStoreUnitID { get; set; } = new Fstoreunitid();
        public Fauxunitid FAuxUnitID { get; set; }
        public string FUnitConvertDir { get; set; } = "1";
        public Fstockid FStockId { get; set; }
        public Fstockplaceid FStockPlaceId { get; set; }
        public bool FIsLockStock { get; set; }
        public bool FIsCycleCounting { get; set; }
        public string FCountCycle { get; set; }
        public string FCountDay { get; set; } = "0";
        public bool FIsMustCounting { get; set; }
        public bool FIsBatchManage { get; set; }
        public Fbatchruleid FBatchRuleID { get; set; }
        public bool FIsKFPeriod { get; set; }
        public bool FIsExpParToFlot { get; set; }
        public string FExpUnit { get; set; }
        public decimal FExpPeriod { get; set; }
        public decimal FOnlineLife { get; set; }
        public decimal FRefCost { get; set; }
        public Fcurrencyid FCurrencyId { get; set; }
        public bool FIsEnableMinStock { get; set; }
        public bool FIsEnableMaxStock { get; set; }
        public bool FIsEnableSafeStock { get; set; }
        public bool FIsEnableReOrder { get; set; }
        public decimal FMinStock { get; set; }
        public decimal FSafeStock { get; set; }
        public decimal FReOrderGood { get; set; }
        public decimal FEconReOrderQty { get; set; }
        public decimal FMaxStock { get; set; }
        public bool FIsSNManage { get; set; }
        public bool FIsSNPRDTracy { get; set; }
        public Fsncoderule FSNCodeRule { get; set; }
        public Fsnunit FSNUnit { get; set; }
        public string FSNManageType { get; set; } = "1";
        public string FSNGenerateTime { get; set; } = "1";
    }

    public class Fstoreunitid
    {
        public string FNumber { get; set; } = "Pcs";
    }

    public class Fauxunitid
    {
        public string FNumber { get; set; }
    }

    public class Fstockid
    {
        public string FNumber { get; set; }
    }

    public class Fstockplaceid
    {
    }

    public class Fbatchruleid
    {
        public string FNumber { get; set; }
    }

    public class Fcurrencyid
    {
        public string FNumber { get; set; }
    }

    public class Fsncoderule
    {
        public string FNumber { get; set; }
    }

    public class Fsnunit
    {
        public string FNumber { get; set; }
    }

    public class Subheadentity2
    {
        public Fsaleunitid FSaleUnitId { get; set; } = new Fsaleunitid();
        public Fsalepriceunitid FSalePriceUnitId { get; set; } = new Fsalepriceunitid();
        public decimal FOrderQty { get; set; }
        public decimal FMinQty { get; set; }
        public decimal FMaxQty { get; set; }
        public decimal FOutStockLmtH { get; set; }
        public decimal FOutStockLmtL { get; set; }
        public decimal FAgentSalReduceRate { get; set; }
        public bool FIsATPCheck { get; set; }
        public bool FIsReturnPart { get; set; }
        public bool FIsInvoice { get; set; }
        public bool FIsReturn { get; set; }
        public bool FAllowPublish { get; set; }
        public bool FISAFTERSALE { get; set; }
        public bool FISPRODUCTFILES { get; set; }
        public bool FISWARRANTED { get; set; }
        public string FWARRANTY { get; set; } = "";
        public string FWARRANTYUNITID { get; set; }
        public string FOutLmtUnit { get; set; } = "SAL";
        public Ftaxcategorycodeid FTaxCategoryCodeId { get; set; }
    }

    public class Fsaleunitid
    {
        public string FNumber { get; set; } = "Pcs";
    }

    public class Fsalepriceunitid
    {
        public string FNumber { get; set; } = "Pcs";
    }

    public class Ftaxcategorycodeid
    {
        public string FNumber { get; set; }
    }

    public class Subheadentity3
    {
        public decimal FBaseMinSplitQty { get; set; }
        public Fpurchaseunitid FPurchaseUnitId { get; set; } = new Fpurchaseunitid();
        public Fpurchasepriceunitid FPurchasePriceUnitId { get; set; } = new Fpurchasepriceunitid();
        public Fpurchaseorgid FPurchaseOrgId { get; set; }
        public Fpurchasegroupid FPurchaseGroupId { get; set; }
        public Fpurchaserid FPurchaserId { get; set; }
        public Fdefaultvendor FDefaultVendor { get; set; }
        public Fchargeid FChargeID { get; set; }
        public bool FIsQuota { get; set; }
        public string FQuotaType { get; set; } = "1";
        public decimal FMinSplitQty { get; set; }
        public bool FIsVmiBusiness { get; set; }
        public bool FEnableSL { get; set; }
        public bool FIsPR { get; set; }
        public bool FIsReturnMaterial { get; set; }
        public bool FIsSourceControl { get; set; }
        public decimal FReceiveMaxScale { get; set; }
        public decimal FReceiveMinScale { get; set; }
        public decimal FReceiveAdvanceDays { get; set; }
        public decimal FReceiveDelayDays { get; set; }
        public decimal FAgentPurPlusRate { get; set; }
        public Fdefbarcoderuleid FDefBarCodeRuleId { get; set; }
        public decimal FPrintCount { get; set; }
        public decimal FMinPackCount { get; set; }
    }

    public class Fpurchaseunitid
    {
        public string FNumber { get; set; } = "Pcs";
    }

    public class Fpurchasepriceunitid
    {
        public string FNumber { get; set; } = "Pcs";
    }

    public class Fpurchaseorgid
    {
        public string FNumber { get; set; }
    }

    public class Fpurchasegroupid
    {
        public string FNumber { get; set; }
    }

    public class Fpurchaserid
    {
        public string FNumber { get; set; }
    }

    public class Fdefaultvendor
    {
        public string FNumber { get; set; }
    }

    public class Fchargeid
    {
        public string FNumber { get; set; }
    }

    public class Fdefbarcoderuleid
    {
        public string FNumber { get; set; }
    }

    public class Subheadentity4
    {
        public string FPlanMode { get; set; }
        public string FBaseVarLeadTimeLotSize { get; set; } = "1";
        public string FPlanningStrategy { get; set; } = "1";
        public Fmfgpolicyid FMfgPolicyId { get; set; } = new Fmfgpolicyid();
        public string FOrderPolicy { get; set; } = "0";
        public Fplanworkshop FPlanWorkshop { get; set; }
        public decimal FFixLeadTime { get; set; }
        public string FFixLeadTimeType { get; set; } = "1";
        public decimal FVarLeadTime { get; set; }
        public string FVarLeadTimeType { get; set; } = "1";
        public decimal FCheckLeadTime { get; set; }
        public string FCheckLeadTimeType { get; set; } = "1";
        public string FOrderIntervalTimeType { get; set; } = "3";
        public decimal FOrderIntervalTime { get; set; }
        public decimal FMaxPOQty { get; set; }
        public decimal FMinPOQty { get; set; }
        public decimal FIncreaseQty { get; set; }
        public string FEOQ { get; set; } = "1";
        public string FVarLeadTimeLotSize { get; set; } = "1";
        public decimal FPlanIntervalsDays { get; set; }
        public decimal FPlanBatchSplitQty { get; set; }
        public string FRequestTimeZone { get; set; } = "0";
        public string FPlanTimeZone { get; set; } = "0";
        public Fplangroupid FPlanGroupId { get; set; }
        public Fplanerid FPlanerID { get; set; }
        public string FCanLeadDays { get; set; } = "0";
        public bool FIsMrpComReq { get; set; }
        public decimal FLeadExtendDay { get; set; }
        public string FReserveType { get; set; } = "1";
        public decimal FPlanSafeStockQty { get; set; }
        public bool FAllowPartAhead { get; set; }
        public decimal FCanDelayDays { get; set; }
        public decimal FDelayExtendDay { get; set; }
        public bool FAllowPartDelay { get; set; }
        public string FPlanOffsetTimeType { get; set; } = "1";
        public string FPlanOffsetTime { get; set; } = "0";
        public Fsupplysourceid FSupplySourceId { get; set; }
        public Ftimefactorid FTimeFactorId { get; set; }
        public Fqtyfactorid FQtyFactorId { get; set; }
    }

    public class Fmfgpolicyid
    {
        public string FNumber { get; set; } = "ZZCL001_SYS";
    }

    public class Fplanworkshop
    {
        public string FNumber { get; set; }
    }

    public class Fplangroupid
    {
        public string FNumber { get; set; }
    }

    public class Fplanerid
    {
        public string FNumber { get; set; }
    }

    public class Fsupplysourceid
    {
        public string FNumber { get; set; }
    }

    public class Ftimefactorid
    {
        public string FNumber { get; set; }
    }

    public class Fqtyfactorid
    {
        public string FNumber { get; set; }
    }

    public class Subheadentity5
    {
        public Fworkshopid FWorkShopId { get; set; }
        public Fproduceunitid FProduceUnitId { get; set; }
        public decimal FFinishReceiptOverRate { get; set; }
        public decimal FFinishReceiptShortRate { get; set; }
        public Fproducebilltype FProduceBillType { get; set; }
        public Forgtrustbilltype FOrgTrustBillType { get; set; }
        public bool FIsProductLine { get; set; }
        public Fbomunitid FBOMUnitId { get; set; }
        public decimal FLOSSPERCENT { get; set; }
        public decimal FConsumVolatility { get; set; }
        public bool FIsMainPrd { get; set; }
        public bool FIsCoby { get; set; }
        public bool FIsECN { get; set; }
        public bool FIssueType { get; set; }
        public string FBKFLTime { get; set; }
        public Fpickstockid FPickStockId { get; set; }
        public Fpickbinid FPickBinId { get; set; }
        public string FOverControlMode { get; set; } = "1";
        public decimal FMinIssueQty { get; set; } = 1;
        public bool FISMinIssueQty { get; set; }
        public bool FIsKitting { get; set; }
        public decimal FIsCompleteSet { get; set; }
        public Fdefaultrouting FDefaultRouting { get; set; }
        public decimal FStdLaborPrePareTime { get; set; }
        public decimal FStdLaborProcessTime { get; set; }
        public decimal FStdMachinePrepareTime { get; set; }
        public decimal FStdMachineProcessTime { get; set; }
        public Fminissueunitid FMinIssueUnitId { get; set; } = new Fminissueunitid();
        public FMDLID FMDLID { get; set; }
        public Fmdlmaterialid FMdlMaterialId { get; set; }
    }

    public class Fworkshopid
    {
        public string FNumber { get; set; }
    }

    public class Fproduceunitid
    {
        public string FNumber { get; set; }
    }

    public class Fproducebilltype
    {
        public string FNumber { get; set; }
    }

    public class Forgtrustbilltype
    {
        public string FNumber { get; set; }
    }

    public class Fbomunitid
    {
        public string FNumber { get; set; }
    }

    public class Fpickstockid
    {
        public string FNumber { get; set; }
    }

    public class Fpickbinid
    {
    }

    public class Fdefaultrouting
    {
        public string FNumber { get; set; }
    }

    public class Fminissueunitid
    {
        public string FNumber { get; set; } = "Pcs";
    }

    public class FMDLID
    {
        public string FNumber { get; set; }
    }

    public class Fmdlmaterialid
    {
        public string FNumber { get; set; }
    }

    public class Subheadentity7
    {
        public Fsubconunitid FSubconUnitId { get; set; }
        public Fsubconpriceunitid FSubconPriceUnitId { get; set; }
        public Fsubbilltype FSubBillType { get; set; }
    }

    public class Fsubconunitid
    {
        public string FNumber { get; set; }
    }

    public class Fsubconpriceunitid
    {
        public string FNumber { get; set; }
    }

    public class Fsubbilltype
    {
        public string FNumber { get; set; }
    }

    public class Subheadentity6
    {
        public bool FCheckIncoming { get; set; }
        public bool FCheckProduct { get; set; }
        public bool FCheckStock { get; set; }
        public bool FCheckReturn { get; set; }
        public bool FCheckDelivery { get; set; }
        public bool FEnableCyclistQCSTK { get; set; }
        public int FStockCycle { get; set; }
        public bool FEnableCyclistQCSTKEW { get; set; }
        public int FEWLeadDay { get; set; }
        public Fincsampschemeid FIncSampSchemeId { get; set; }
        public Fincqcschemeid FIncQcSchemeId { get; set; }
        public Finspectgroupid FInspectGroupId { get; set; }
        public Finspectorid FInspectorId { get; set; }
        public bool FCheckEntrusted { get; set; }
    }

    public class Fincsampschemeid
    {
        public string FNumber { get; set; }
    }

    public class Fincqcschemeid
    {
        public string FNumber { get; set; }
    }

    public class Finspectgroupid
    {
        public string FNumber { get; set; }
    }

    public class Finspectorid
    {
        public string FNumber { get; set; }
    }

    public class Fentityauxpty
    {
        public Int64 FEntryID { get; set; }
        public Fauxpropertyid FAuxPropertyId { get; set; }
        public bool FIsEnable1 { get; set; }
        public bool FIsComControl { get; set; }
        public bool FIsAffectPrice1 { get; set; }
        public bool FIsAffectPlan1 { get; set; }
        public bool FIsAffectCost1 { get; set; }
        public bool FIsMustInput { get; set; }
        public string FValueType { get; set; }
    }

    public class Fauxpropertyid
    {
        public string FNUMBER { get; set; }
    }

    public class Fentityinvpty
    {
        public string FEntryID { get; set; }
        public Finvptyid FInvPtyId { get; set; }
        public bool FIsEnable { get; set; } = true;
        public bool FIsAffectPrice { get; set; }
        public bool FIsAffectPlan { get; set; }
        public bool FIsAffectCost { get; set; }
    }

    public class Finvptyid
    {
        public string FNumber { get; set; }
    }
}